package com.sc.springboot.dao;

import com.sc.springboot.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {

    @Insert("insert into user (user_name, pass_word) VALUE (#{userName}, #{passWord})")
    void add(User user);

    @Delete("delete from user where 1 = 1 and id = #{id}")
    void delete(int id);

    @Update("update user set user_name = #{userName}, pass_word = #{passWord} where 1 = 1 and id = #{id};")
    void update(User user);

    @Select("select * from user")
    @Results({
            @Result(property = "userName",  column = "user_name"),
            @Result(property = "passWord", column = "pass_word")
    })
    List<User> findAll();

    @Select("select * from user where 1 = 1 and user_name = #{userName}")
    @Results({
            @Result(property = "userName",  column = "user_name"),
            @Result(property = "passWord", column = "pass_word")
    })
    User findByUserName(String userName);

}
